import { cloneDeep } from 'lodash';

/**
 * 数据还原
 * @param data any[]
 * @returns Array
 */
const reduction = (data: any) => {
  let item = cloneDeep(data);
  let pageArr: any = [];
  if (item.Type === 100) {
    // 页面
    let page: {
      type: number;
      OutId: string;
      Name: string;
      Route: string;
      list: any[];
    } = {
      type: item.Type,
      OutId: item.OutId,
      Name: item.ObjectName,
      Route: item.ObjectValue,
      list: [],
    };
    // 分组赛选
    Array.isArray(item.Children) &&
      item.Children.forEach((val: any) => {
        // 分组
        let group: {
          type: number;
          tag: string;
          name: string;
          parentOutId: string;
          list: any[];
        } = {
          type: val.ObjectValue,
          tag: val.OutId,
          name: val.ObjectName,
          parentOutId: val.ParentOutId,
          list: [],
        };
        Array.isArray(val.Children) &&
          val.Children.forEach((one: any) => {
            // 动作
            group.list.push({
              id: one.OutId,
              name: one.ObjectName,
              value: one.ObjectValue,
            });
          });
        page.list.push(group);
      });
    pageArr.push(page);
  }
  return pageArr[0];
};

export { reduction };
